const sleep = async ms => {
  return new Promise(reslove => {
    setTimeout(() => {
      reslove(true);
    });
  }, ms);
};
module.exports = {
  login(ctx) {
    const { username = "", password = "" } = ctx.request.body;
    if (
      username.trim() === "melissahuang" &&
      password.trim() === "melissa1000"
    ) {
      const token = username + Date.now();
      ctx.session.token = token;
      ctx.body = {
        code: 2000,
        desc: "登录成功",
        data: {
          username: username,
          token
        }
      };
    } else {
      ctx.body = {
        code: 4030,
        desc: "登录失败",
        data: {
          username: username
        }
      };
    }
  },
  async userList(ctx) {
    await sleep(1000);
    ctx.body = {
      code: 2000,
      desc: "查询成功",
      data: [
        {
          id: 101,
          createTime: 1332412463155,
          account: "Patricia",
          companyName:
            "Ycshhpnslt Xzrinocgen Ungulvm Iskkzn Vanjg Vlociufih Doxbbqvg Hnchrht Exio",
          accessKey: "Sarah",
          marked: "Mary",
          status: "freeze"
        },
        {
          id: 102,
          createTime: 1586484937639,
          account: "Richard",
          companyName: "Lfnwo Ennuoilih Mmk Rrisiqo Fuye Lzatqrazg Igoudbt",
          accessKey: "Maria",
          marked: "Larry",
          status: "unfreeze"
        },
        {
          id: 103,
          createTime: 913136817413,
          account: "David",
          companyName: "Kfqnlkvce Gwrzll Iulfxxmrl Htqvjensh Jjxl Swly Omv",
          accessKey: "Eric",
          marked: "Timothy",
          status: "unfreeze"
        },
        {
          id: 104,
          createTime: 1162213742469,
          account: "Margaret",
          companyName: "Byyuk Cpxgmwwfyb Takeifc Qdtvbomk Plbf Gxzl Tbsynbu",
          accessKey: "Linda",
          marked: "Eric",
          status: "freeze"
        },
        {
          id: 105,
          createTime: 120711774668,
          account: "Thomas",
          companyName: "Vhldhz Yjug Dfqzhgix Cnjxmfhnxl Uzycrrk Frwqwd Jbqhvh",
          accessKey: "Maria",
          marked: "Daniel",
          status: "unfreeze"
        },
        {
          id: 106,
          createTime: 242140116335,
          account: "Donald",
          companyName: "Exhzitd Dhwkyvbyhy Llsohtwkln Nxn Ljwpcrqt",
          accessKey: "Barbara",
          marked: "John",
          status: "freeze"
        },
        {
          id: 107,
          createTime: 1171959995102,
          account: "Mark",
          companyName:
            "Udhxq Ezdifekktf Csoeuih Dkgisbbh Hkigzcofy Ubdrptar Uznpsd Tfuonoo",
          accessKey: "Eric",
          marked: "Eric",
          status: "freeze"
        },
        {
          id: 108,
          createTime: 997252486410,
          account: "Kenneth",
          companyName: "Zdugsqmu Wpf Pxdol Jyvhysyw Udimur Jbrjthbg Hrhrqld",
          accessKey: "Mary",
          marked: "Richard",
          status: "unfreeze"
        },
        {
          id: 109,
          createTime: 561285783983,
          account: "Angela",
          companyName: "Osxc Qslalyq Qghsipwyy Mjbqmf Hcgpiokeh",
          accessKey: "Michelle",
          marked: "Betty",
          status: "unfreeze"
        },
        {
          id: 110,
          createTime: 126188694095,
          account: "Larry",
          companyName:
            "Qcbupfn Zxxkjln Hfcovqxuy Yergvy Itpvg Tvvwjrg Kkedviff Xcbzghobz",
          accessKey: "Sharon",
          marked: "Thomas",
          status: "unfreeze"
        }
      ],
      pageInfo: {
        totalSize: 100,
        totalPages: 10,
        size: "10",
        first: true,
        last: false,
        number: "1010"
      }
    };
  }
};
